package mediadisplay.ui.spacecontrols 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import mediadisplay.viewerarea.ScreenText;
	/**
	 * ...
	 * @author Anders Figenschow selvfølgelig
	 */
	public class SpaceControl extends Sprite
	{
		private var _soundGraph:SoundGraph;
		private var thingy:ScreenText;
		private var steps:int = 10;
		
		public function SpaceControl(soundGraph:SoundGraph) 
		{
			_soundGraph = soundGraph;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
			
		}
		
		public function setObjectToMove(thingy:ScreenText):void {
			this.thingy = thingy;
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			var left:MovementButton = new MovementButton(MovementButton.LEFT);
			addChild(left);
			left.y = 20;
			left.addEventListener(MouseEvent.CLICK, movementButtonClicked);
			var right:MovementButton = new MovementButton(MovementButton.RIGHT);
			addChild(right);
			right.x = 40;
			right.y = 20;
			right.addEventListener(MouseEvent.CLICK, movementButtonClicked);
			var up:MovementButton = new MovementButton(MovementButton.UP);
			addChild(up);
			up.x = 20;
			up.addEventListener(MouseEvent.CLICK, movementButtonClicked);
			var down:MovementButton = new MovementButton(MovementButton.DOWN);
			addChild(down);
			down.x = 15;
			down.y = 40;
			down.addEventListener(MouseEvent.CLICK, movementButtonClicked);
			var forward:MovementButton = new MovementButton(MovementButton.FORWARD);
			addChild(forward);
			forward.x = 90;
			forward.y = 10;
			forward.addEventListener(MouseEvent.CLICK, movementButtonClicked);
			var back:MovementButton = new MovementButton(MovementButton.BACK);
			addChild(back);
			back.x = 85;
			back.y = 30;
			back.addEventListener(MouseEvent.CLICK, movementButtonClicked);
		}
		
		private function movementButtonClicked(e:MouseEvent):void 
		{
			//trace("clicked: " + e.currentTarget.name);
			if (thingy == null) {
				trace("no object chosen for movement.");
				return;
			}
			switch (e.currentTarget.name) 
			{
				case MovementButton.LEFT:
					thingy.x -= steps;
				break;
				case MovementButton.RIGHT:
					thingy.x += steps;
				break;
				case MovementButton.UP:
					thingy.y -= steps;
				break;
				case MovementButton.DOWN:
					thingy.y += steps;
				break;
				case MovementButton.FORWARD:
					thingy.z += steps;
				break;
				case MovementButton.BACK:
					thingy.z -= steps;
				break;
				default:
					trace("?");
				break;
			}
		}
		
	}

}



